﻿<%@ WebHandler Language="C#" Class="uploads_img" %>

using System;
using System.Web;
using System.IO;
using System.Drawing;
using System.Data;
using System.Web.Script.Serialization;
public class uploads_img : IHttpHandler {

    public void ProcessRequest(HttpContext context)
    {
        if (true)
        {
            context.Response.ContentType = "text/plain";
            result result = new result();
            string fileNewName = string.Empty;
            string filePath = string.Empty;
            string filePath2 = string.Empty;
            HttpFileCollection files = context.Request.Files;
            if (files.Count > 0)
            {
                //设置文件名
                fileNewName = DateTime.Now.ToString("yyyyMMddHHmmssff") + "_" + System.IO.Path.GetFileName(files[0].FileName);
                //保存文件     
                files[0].SaveAs(context.Server.MapPath("../Files/" + fileNewName));
                filePath = "../Files/" + fileNewName;
                filePath2= "/Files/" + fileNewName;
                result.code = "100";
                result.msg = "文件上传成功！";
                result.url = filePath;
                result.url2 = filePath2;
            }
            else
            {
                result.code = "200";
                result.msg = "文件上传失败！";
            }
            context.Response.Write(new JavaScriptSerializer().Serialize(result));
            context.Response.End();
        }
    }
    public class result
    {
        public string code { get; set; }
        public string msg { get; set; }
        public string url { get; set; }
        public string url2 { get; set; }
    }
    public bool IsReusable {
        get {
            return false;
        }
    }

}